package com.kehutong.charge.service.impl;

import com.kehutong.charge.entity.ChargeBillCommunity;
import com.kehutong.charge.entity.ChargeFeeChange;
import com.kehutong.charge.service.ChargeFeeChangeService;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;
import org.coraframework.orm.jdbc.execute.entity.FindPage;

import java.util.List;

/**
 * @author joneRon
 * @Title: kht
 * @Description: 费用信息服务接口
 * @date 2021/7/16
 */
public class ChargeFeeChangeServiceImpl implements ChargeFeeChangeService {

    @Inject
    private JdbcSession jdbcSession;


    @Override
    public Page<ChargeFeeChange> findPage(JSONObject jsonObject) {
        FindPage<ChargeFeeChange> find = jdbcSession.findPage(ChargeFeeChange.class)
                .eq("deleted", false)
                .eq(jsonObject,"status")
                .order("createTime", "desc");

        find.page(jsonObject);

        return find.exe();
    }

    @Override
    public List<ChargeFeeChange> findList(JSONObject jsonObject) {
        return jdbcSession.findArray(ChargeFeeChange.class)
                .eq("deleted", false)
                .eq(jsonObject,"serviceNo")
                .exe();
    }

    @Override
    public Object save(ChargeFeeChange chargeFeeChange) throws Exception {

        chargeFeeChange.setStatus(true);
        return jdbcSession.insert(chargeFeeChange);
    }

    @Override
    public Object update(ChargeFeeChange chargeFeeChange) {
        return jdbcSession.updateById(chargeFeeChange);
    }

    @Override
    public Object deleteById(String id) {
        ChargeBillCommunity result = Pool.get(ChargeBillCommunity.class, id);
        if (result != null) {
            result.setDeleted(true);
            jdbcSession.updateById(result);
        }
        return 1;
    }
}
